" vim:ft=vim
" Test Exceptions
Before;
let builtins = object#except#builtins()
let BaseException = builtins.BaseException
let Exception = builtins.Exception


Execute(BaseException);
let e = object#new(BaseException)
Log object#dir(e)
AssertEqual e.args, []
AssertThrows call add(g:e.args, 1)
AssertEqual 1, object#bool(e), 'exception is truthy'
AssertEqual object#repr(e), 'BaseException([])'
AssertEqual object#str(e), ''


Execute(BaseException with more args);
let e = object#new(BaseException, 'msg')
AssertEqual object#str(e), 'msg'
AssertEqual object#repr(e), 'BaseException([''msg''])'


Execute(Raise a BaseException);
AssertThrows call object#raise(g:BaseException)
Assert g:vader_exception =~# 'BaseException'


Execute(Raise an Exception);
AssertThrows call object#raise(g:Exception)
Assert g:vader_exception =~# 'Exception'


Execute(Frequently used raisers);
let raisers = [
      \ 'Exception',
      \ 'TypeError',
      \ 'AttributeError',
      \ 'ValueError',
      \ 'StopIteration',
      \]

for raiser in raisers
  AssertThrows call object#{g:raiser}()
  Assert g:vader_exception =~# raiser
endfor
